package com.amigo.views.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amigo.R;
import com.amigo.helper.Constants;
import com.amigo.helper.ImageLoader;
import com.amigo.views.SquareImageView;

public class AmigoListViewAdapter extends BaseAdapter {
	 
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;
    
    public AmigoListViewAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }
 
    public int getCount() {
        return data.size();
    }
 
    public Object getItem(int position) {
        return position;
    }
 
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_item, null);

      TextView user_name = (TextView) vi.findViewById(R.id.user_name);
      TextView user_location = (TextView) vi.findViewById(R.id.user_location);
     SquareImageView thumb_image=(SquareImageView)vi.findViewById(R.id.dp_user);
 
        HashMap<String, String> item = new HashMap<String, String>();
        
        item = data.get(position);
 
        //Setting all values in listview
        user_name.setText(item.get("user_name"));
        user_location.setText(item.get("user_location"));
        imageLoader.DisplayImage(Constants.base_url + item.get("image_url"), thumb_image);
        return vi;
    }
}